<template>
	<view class="resourceList">

		<uni-row style="margin-top: 8rpx;">
			<view class="uni-padding-wrap uni-common-mt">
				<uni-segmented-control :current="current" :values="items" style-type="button" active-color="#007aff"
					@clickItem="onClickItem" />
			</view>
		</uni-row>
		<uni-row>
			<uni-col :span="22" style="padding-left: 5rpx;padding-top: 12rpx;">
				<button style="background-color: #94bcff;" size="mini" @click="addButtonClick">新增</button>
			</uni-col>
			<uni-col :span="2" style="padding-top: 7rpx;">
				<uni-icons type="list" size="32"></uni-icons>
			</uni-col>
		</uni-row>

		<view v-for="(item,index) in repairOrderList" style="margin-top: 30rpx;">
			<uni-row class="resourceList-uni-row">
				<text style="font-size: 18px;font-weight:bold;">
					编号:&nbsp;&nbsp;&nbsp;{{item.number}}
				</text>
			</uni-row>
			<uni-row class="resourceList-uni-row">
				<text class="resourceList-text">
					报修时间:&nbsp;&nbsp;&nbsp;{{item.reportRepairTime}}
				</text>
			</uni-row>
			<uni-row class="resourceList-uni-row">
				<text class="resourceList-text">
					设备:&nbsp;&nbsp;&nbsp;{{item.equipmentName}}
				</text>
			</uni-row>
			<uni-row class="resourceList-uni-row">
				<text class="resourceList-text">
					完成时间:&nbsp;&nbsp;&nbsp;{{item.finishTime}}
				</text>
			</uni-row>
			<uni-row class="resourceList-uni-row">
				<text class="resourceList-text">
					维修人:&nbsp;&nbsp;&nbsp;{{item.repairUserName}}
				</text>
			</uni-row>
			<uni-row class="resourceList-uni-row">
				<uni-col :span="18">
					<text class="resourceList-text">
						状态:&nbsp;&nbsp;&nbsp;
						<uni-tag style='margin-left: 30rpx;' :text="item.status=='A'?'暂存':
									item.status=='B'?'报修中':
									item.status=='C'?'维修完成':
									 item.status=='D'?'已验收':''" :type="item.status=='A'?'':
									item.status=='B'?'error':
									item.status=='C'?'primary':
									 item.status=='D'?'success':''" />
					</text>
				</uni-col>
				<uni-col :span="6">
					<button style="padding: 0rpx; height: 57rpx;width: 120rpx;" plain="true" size="mini" type="primary"
						@click="editRepairOrder(item.id)">
						<text style="font-size: 4;">修改</text>
					</button>
				</uni-col>
			</uni-row>
		</view>
		<uni-load-more :status="loadStatus" />
		<repairOrderForm ref="repairOrderForm"> </repairOrderForm>
	</view>

</template>

<script>
	import {
		listRepairOrder,
		getRepairOrder,
		delRepairOrder,
		addRepairOrder,
		updateRepairOrder
	} from "@/api/equipment/repairOrder";
	import repairOrderForm from "@/pages/equipment/repairOrder/form.vue";
	import {
		getUserProfile
	} from "@/api/system/user"
	import {
		getDicts
	} from "@/api/system/dict/data";
	export default {
		components: {
			repairOrderForm
		},
		data() {
			return {
				queryParams: {
					pageSize: 5,
					pageNum: 1,
					params: {},
					status: "B"
				},
				//设备维修单列表
				repairOrderList: [],
				user: {},
				loadStatus: "more",
				items: ['暂存', '报修中', '已完成'],
				current: 1,
			}
		},
		created() {
			this.getUser();
			this.getList();
		},
		onReachBottom() {
			this.clickLoadMore()
		},
		methods: {
			/** 查询列表 */
			getList() {
				this.queryParams.repairUserId = this.user.userId
				this.queryParams.createBy = this.user.userName;
				listRepairOrder(this.queryParams).then(response => {
					let total = response.total;
					let list = response.rows;
					//已查询出来的和新查询的 大于等于total总页数，表示no-more
					if (list.length + this.repairOrderList.length >= total) {
						this.loadStatus = "no-more"
					} else {
						this.loadStatus = "more"
					}

					if (this.repairOrderList.length > 0) {
						this.repairOrderList = this.repairOrderList.concat(list)
					} else {
						this.repairOrderList = list;
					}

				})
			},
			getUser() {
				getUserProfile().then(response => {
					this.user = response.data
				})
			},
			addButtonClick() {
				this.$refs.repairOrderForm.openPopup();
			},
			queryClick() {
				this.queryParams.pageNum = 1
				this.repairOrderList = []
				this.getList();
			},
			clickLoadMore() {
				if (this.loadStatus === "no-more") {
					return;
				}
				this.loadStatus = "loading"
				this.queryParams.pageNum += 1;
				this.getList();
			},
			onClickItem(e) {
				if (this.current !== e.currentIndex) {
					this.current = e.currentIndex
				}
				if(this.current==0){
					this.queryParams.status='A';
				}else  if(this.current==1){
					this.queryParams.status='B';
				}else  if(this.current==2){
					this.queryParams.status='C,D';
				}else{
					this.queryParams.status='B';
				}
				this.repairOrderList=[];
				this.getList();
			},
			//点击修改
			editRepairOrder(id){
				this.$refs.repairOrderForm.openPopup(id);
			},
		},
	}
</script>

<style>
	.resourceList-uni-row {
		margin-bottom: 12rpx;
	}

	.resourceList-text {
		font-size: 16px;
	}

	.resourceList {
		margin-left: 10px;

	}
</style>
